package com.xzq.action;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.CookiesAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 实现在框架中使用	session等servlet原生对象的另一种方式
 */
public class BaseAction extends ActionSupport implements ServletRequestAware,SessionAware,RequestAware,ApplicationAware,ServletContextAware{
	//protected 让子类可以访问
	//自定义一个session属性	由于实现了SessionAware接口
	//struts2会自动地调用setSession()方法 把原生的servlet session 传值
	protected Map<String, Object> session;
	protected Map<String, Object> application;
	protected Map<String, Object> request;
	protected ServletContext context;
	protected ServletRequest sere;
	
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
		
	}

	@Override
	public void setApplication(Map<String, Object> application) {
		this.application = application;
		
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	@Override
	public void setServletContext(ServletContext context) {
		this.context = context;
		
	}
	
	public String getRealPath(String path){
		return context.getRealPath(path);//转换成web应用所在的系统路径
	}

	@Override
	public void setServletRequest(HttpServletRequest sere) {
		this.sere = sere;
		
	}

}
